﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Serilog.Events;
using Serilog;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
using NLog.Web;

namespace Apps.Extensions.Logger
{
    public static class NlogExtension
    {
        public static WebApplicationBuilder AddNLogExtension(this WebApplicationBuilder builder)
        {

            var nlogConfig = builder.Configuration.GetSection("NLog");
            NLog.LogManager.Configuration = new NLogLoggingConfiguration(nlogConfig);
            //清空其他日志Providers
            builder.Logging.ClearProviders();
            //该配置用来指定使用ASP.NET Core 默认的日志过滤器
            var nlogOptions = new NLogAspNetCoreOptions() { RemoveLoggerFactoryFilter = false };
            builder.Host.UseNLog(nlogOptions); //启用NLog
            return builder;
        }
    }
}
